package de.szut.ita13sommerfeld.apacheanalyser.libaries;

import java.util.Set;

import de.szut.ita13sommerfeld.apacheanalyser.apachelog.User;

public class UserLibary extends Libary<String, User> {

	private static final long serialVersionUID = 1L;
	private User mostDataUsageUser;
	private User mostEntriesUser;

	public UserLibary() {
		mostDataUsageUser = null;
		mostEntriesUser = null;
	}
		
	/**
	 * prints out all values of the resource libary
	 */
	public void showValues() {
		Set<Entry<String, User>> entrySet = entrySet();
		for(Entry<String, User> entry : entrySet) {
			System.out.println(entry.getKey() + " " + entry.getValue().getFirstAction().getDateString());
		}
	}
	
	/**
	 * 
	 * @return returns the User with the most data usage
	 */
	public User getMostDataUsageUser() {
		Set<Entry<String, User>> entrySet = entrySet();
		for(Entry<String, User> e : entrySet) {
			User currentUser = e.getValue();
			if(mostDataUsageUser == null) 
				mostDataUsageUser = currentUser;
			else {
				if(mostDataUsageUser.getTotalsize() < currentUser.getTotalsize()) {
					mostDataUsageUser = currentUser;
				}
			}
		}
		return mostDataUsageUser;
	}
	
	/**
	 * 
	 * @return returns the User with the most entries
	 */
	public User getMostEntriesUser() {
		Set<Entry<String, User>> entrySet = entrySet();
		for(Entry<String, User> e : entrySet) {
			User currentUser = e.getValue();
			if(mostEntriesUser == null) 
				mostEntriesUser = currentUser;
			else {
				if(mostEntriesUser.getEntries().size() < currentUser.getEntries().size()) {
					mostEntriesUser = currentUser;
				}
			}
		}
		return mostEntriesUser;
	}
}
